<?php
/**
 * Created by PhpStorm.
 * User: jimmy
 * Date: 2017/8/3
 * Time: 上午10:30
 */
require  'ini.php';
$id = $_GET['pid'];
if($id)
{

    //查询productId
    $id_product = $db->select('product',['product_id'],['erp_number'=>$id]);
    if(!$id_product)
    {
        exit("没有找到该产品");
    }
    $id_product = array_column($id_product,'product_id');
    $id_product = implode(',',$id_product);

    $yesMon = date('Y-m-d',strtotime('-1 month'));
    //查询order最多的产品
    $sql ="select `product_id`,count(*) as count from `order` where product_id in ($id_product) and add_time > '$yesMon'  group by product_id order by count desc limit 1";
    $res =  $db->query($sql)->fetchAll(\PDO::FETCH_ASSOC);
    if(isset($res[0]['product_id']))
    {
        $product_id = $res[0]['product_id'];
        $map['product_id'] =$product_id;
    }
    else{
        $map['erp_number'] = $id;
        $map['content[!]'] ="";
        $map['is_del'] = 0;
    }

    $info  =  $db->get('product',['content'],$map);
    if($info)
    {
        echo $info['content'];
    }
    else{
        echo '该产品详情暂无内容';
    }
}




